import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },

  {
    path: '/404',
    component: () => import('@/views/404'),
    hidden: true
  },

  // {
  //   path: '/',
  //   component: Layout,
  //   redirect: '/dashboard',
  //   children: [
  //     {
  //       path: 'dashboard',
  //       name: 'Dashboard',
  //       component: () => import('@/views/dashboard/index'),
  //       meta: { title: 'Dashboard', icon: 'dashboard' }
  //     }
  //   ]
  // },
  // {
  //   path: '/example',
  //   component: Layout,
  //   redirect: '/example/table',
  //   name: 'Example',
  //   meta: { title: 'Example', icon: 'el-icon-s-help' },
  //   children: [
  //     {
  //       path: 'chat',
  //       name: 'chat',
  //       component: () => import('@/views/chat/chat.vue'),
  //       meta: { title: 'chat', icon: 'dashboard' }
  //     },
  //     {
  //       path: 'table',
  //       name: 'Table',
  //       component: () => import('@/views/table/index'),
  //       meta: { title: 'Table', icon: 'table' }
  //     },
  //     {
  //       path: 'draw',
  //       name: 'Draw',
  //       component: () => import('@/views/draw/draw.vue'),
  //       meta: { title: '标绘集合' }
  //     },
  //     {
  //       path: 'freeLine',
  //       name: 'freeLine',
  //       component: () => import('@/views/FreeLine/CreateFreeLine.vue'),
  //       meta: { title: '自由线' }
  //     }
  //   ]
  // },
  // {
  //   path: '/nested',
  //   component: Layout,
  //   redirect: '/nested/menu1',
  //   name: 'Nested',
  //   meta: {
  //     title: 'Nested',
  //     icon: 'nested'
  //   },
  //   children: [
  //     {
  //       path: 'menu1',
  //       component: () => import('@/views/nested/menu1/index'), // Parent router-view
  //       name: 'Menu1',
  //       meta: { title: 'Menu1' }
  //     },
  //     {
  //       path: 'menu2',
  //       component: () => import('@/views/nested/menu2/index'),
  //       name: 'Menu2',
  //       meta: { title: 'menu2' }
  //     }
  //   ]
  // },
  //

  // 404 page must be placed at the end !!!
  { path: '*', redirect: '/404', hidden: true }
]

export const jdysRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/jdys',
    name: '节点要素',
    meta: {
      title: '节点要素',
      icon: 'nested'
    },
    children: [
      {
        path: 'basics',
        name: 'basics',
        component: () => import('@/views/jdys/basicContent.vue'),
        meta: { title: '基础信息', icon: 'dashboard' }
      },
      {
        path: 'zzsl',
        name: 'zzsl',
        component: () => import('@/views/jdys/zzStrength.vue'),
        meta: { title: '作战实力', icon: 'dashboard' }
      },
      {
        path: 'jdys',
        name: 'jdys',
        component: () => import('@/views/jdys/index.vue'),
        meta: { title: '节点要素', icon: 'dashboard' }
      },
    ]
  },
]

const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({ y: 0 }),
  routes: [...constantRoutes, ...jdysRoutes]
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export default router
